n, m = map(int, input().split())
s = []
t = set()
for _ in range(n):
    s.append(input())
for _ in range(m):
    t.add(input())


def dfs(word, start_index):
    if len(word) > 16:
        return
    if start_index == n:
        if len(word) > 3 and word not in t:
            print(word)
            return True
        else:
            return False
    # 加几个__
    for count in range(1, 17):
        if count + len(word) > 16: break
        if dfs(word + "_" * count + s[start_index], start_index + 1):
            return True


if not dfs(s[0], 1):
    print(-1)
